package com.ngkj.zmfptback.sys.util;

import cn.hutool.json.JSONUtil;
import com.ngkj.zmfptCommon.common.util.ResultEnum;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author ChenHN
 * @since 2021/12/1 creation
 **/
public class ResultUtil {

    public static void responseJson(HttpServletResponse response, ResultEnum resultEnum) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter writer = response.getWriter();
        HashMap<String, Object> map = new HashMap<>();
        map.put("code",resultEnum.getCode());
        map.put("message",resultEnum.getMessage());
        String jsonStr = JSONUtil.toJsonStr(map);
        writer.print(jsonStr);
    }

    public static void responseJson(HttpServletResponse response,HashMap<String,Object> map) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter writer = response.getWriter();
        String jsonStr = JSONUtil.toJsonStr(map);
        writer.print(jsonStr);
    }



}
